//
//  WebViewViewController.m
//  WebView
//

#import "WebViewViewController.h"

@implementation WebViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	
	CGRect webRect = CGRectMake(10, 10, 300, 400);
	UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
	
	myWebView.delegate = self;

	myWebView.scalesPageToFit = NO;
	NSString *htmlPath = [[NSBundle mainBundle]
						  pathForResource:@"myPage"
						  ofType:@"html"];
	NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath
													  encoding:NSUTF8StringEncoding
														 error:nil];

	[myWebView loadHTMLString:htmlContent baseURL:nil];
	
	[self.view addSubview:myWebView];
	[myWebView release];
}

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType {
	
	NSURL *pageURL = [request URL];
	if (([[pageURL scheme] isEqualToString:@"http"])
		&& (navigationType == UIWebViewNavigationTypeLinkClicked)) {
		[[UIApplication sharedApplication] openURL:pageURL];
		return NO;
	}
	return YES;
}

- (void)dealloc {
    [super dealloc];
}

@end
